Imports capaLogica
Imports PrintDataGridView

Class VentanaAgregarNota
    Dim idGrupo As Integer = 0
    Dim estaCargado As Boolean = False
    Dim listaEstudiantes As New List(Of Estudiante)

    Public Sub New(ByVal pidGrupo As Integer)
        InitializeComponent()
        Me.idGrupo = pidGrupo

    End Sub

    Private Sub VentanaAgregarNota_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        LlenarEstudiantes()
    End Sub

    Private Sub LlenarEstudiantes()
        Dim i As Integer = 0
        Dim c As Integer

        Try
            ' Me.DataGridViewAgregarNota.DataSource


            Me.listaEstudiantes = GestorVerNotas.LevantarEstudiantesXGrupo(idGrupo)

            Me.DataGridViewAgregarNota.Columns.Add("Nombre", "Nombre")

            'agrega las columnas de rubros
            Dim componente As ComponenteEvaluacion = Me.listaEstudiantes.Item(0).Notas
            For Each componente In componente.ListaRubros
                If componente.Nombre <> "Nombre" Then
                    Me.DataGridViewAgregarNota.Columns.Add(componente.Nombre, componente.Nombre)
                End If
            Next

            'agregamos una columna de nota total
            Me.DataGridViewAgregarNota.Columns.Add("NOTA", "NOTA")
            Me.DataGridViewAgregarNota.Columns.Add("RENDIMIENTO", "RENDIMIENTO")

            'hace que las columnas no sean sorteables
            For Each col As DataGridViewColumn In DataGridViewAgregarNota.Columns
                col.SortMode = DataGridViewColumnSortMode.NotSortable
            Next

            '
            For i = 0 To Me.listaEstudiantes.Count - 1

                componente = Me.listaEstudiantes(i).Notas
                Me.DataGridViewAgregarNota.Rows.Add()
                Me.DataGridViewAgregarNota.Rows(i).Cells("Nombre").Value = Me.listaEstudiantes(i).Nombre & " " & Me.listaEstudiantes(i).PrimerApellido & " " & Me.listaEstudiantes(i).SegundoApellido

                For c = 1 To componente.ListaRubros.Count

                    Me.DataGridViewAgregarNota.Rows(i).Cells(c).Value = componente.ListaRubros(c - 1).CalcularNota

                Next
                Me.DataGridViewAgregarNota.Rows(i).Cells(c).Value = componente.CalcularNota()
                Me.DataGridViewAgregarNota.Rows(i).Cells(c + 1).Value = componente.CalcularRendimiento()

            Next


        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try

        estaCargado = True
    End Sub

    Private Sub BtnCancelar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnAceptar.Click
        Me.estaCargado = False
        Me.Dispose()
    End Sub

    Private Sub DataGridViewAgregarNota_CellMouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellMouseEventArgs) Handles DataGridViewAgregarNota.CellMouseDoubleClick
        Dim indexRubro As Integer
        indexRubro = Me.DataGridViewAgregarNota.SelectedCells.Item(0).ColumnIndex
        Dim v As New VentanaAgregarEvaluacion(idGrupo, indexRubro)
        v.ShowDialog()
        Me.actualizarEstudiantes()

    End Sub

    Private Sub actualizarEstudiantes()
        Dim i As New Integer
        Dim c As New Integer
        Dim componente As ComponenteEvaluacion
        For i = 0 To Me.listaEstudiantes.Count - 1
            Me.listaEstudiantes = GestorVerNotas.LevantarEstudiantesXGrupo(idGrupo)
            componente = Me.listaEstudiantes.Item(i).Notas

            For c = 1 To componente.ListaRubros.Count

                Me.DataGridViewAgregarNota.Rows(i).Cells(c).Value = componente.ListaRubros.Item(c - 1).CalcularNota

            Next
            Me.DataGridViewAgregarNota.Rows(i).Cells(c).Value = componente.CalcularNota()
            Me.DataGridViewAgregarNota.Rows(i).Cells(c + 1).Value = componente.CalcularRendimiento()
        Next
    End Sub

    Private Sub btnImprimir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnImprimir.Click
        PrintDGV.Print_DataGridView(DataGridViewAgregarNota)
    End Sub

End Class